package com.yfp.operation.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.operation.domain.dto.*;
import com.yfp.operation.domain.vo.*;
import com.yfp.operation.service.MarCouponPackService;
import com.yfp.operation.domain.dto.*;
import com.yfp.operation.domain.vo.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 优惠券礼包
 */
@RestController
@RequestMapping("marCouponPack")
@Tag(name = "优惠券礼包-pc")
public class MarCouponPackController extends BaseController {

    @Resource
    private MarCouponPackService marCouponPackService;

    @PostMapping
    @Operation(summary = "创建优惠券礼包")
    public R<Void> createCouponPack(@RequestBody MarCouponPackDTO marCouponPack) {
        marCouponPackService.createCouponPack(marCouponPack);
        return R.ok();
    }

    @GetMapping
    @Operation(summary = "查询优惠券礼包活动列表")
    public R<TableDataInfo<MarCouponPackVO>> listCouponPack(MarCouponPackReqDTO marCouponPackReqDTO) {
        // 查询前先检测并更新所有优惠券礼包状态
        marCouponPackService.checkAndUpdateAllStatus();
        TableDataInfo<MarCouponPackVO> marCouponPackVOS = marCouponPackService.listCouponPack(marCouponPackReqDTO);
        return R.ok(marCouponPackVOS);
    }

    @GetMapping("/{id}")
    @Operation(summary = "查询优惠券礼包活动详情")
    public R<MarCouponPackInfoVO> getCouponPackById(@PathVariable Long id) {
        MarCouponPackInfoVO marCouponPackVOS = marCouponPackService.getCouponPackById(id);
        return R.ok(marCouponPackVOS);
    }

    @PutMapping("/status")
    @Operation(summary = "更新优惠券礼包活动状态")
    public R<Void> updateStatusById(@RequestBody MarCouponPackUpdateStatusReqDTO couponPackUpdateStatusReqDTO) {
        marCouponPackService.updateStatusById(couponPackUpdateStatusReqDTO);
        return R.ok();
    }

    @GetMapping("/list/pack-detail/{id}")
    @Operation(summary = "查询优惠券礼包详情列表")
    public R<TableDataInfo<MarCouponPackDetailVO>> listPackDetailById(@PathVariable("id") Long id) {
        TableDataInfo<MarCouponPackDetailVO> marCouponPackVOS = marCouponPackService.listPackDetailById(id);
        return R.ok(marCouponPackVOS);
    }

    @GetMapping("/list/receive-user")
    @Operation(summary = "查询已领取用户列表")
    public R<TableDataInfo<MarCouponPackReceiveUserVO>> listReceiveUserByReq(MarCouponPackReceiveUserReqDTO marCouponReceiveUserReqDTO) {
        TableDataInfo<MarCouponPackReceiveUserVO> marCouponPackVOS = marCouponPackService.listReceiveUserByReq(marCouponReceiveUserReqDTO);
        return R.ok(marCouponPackVOS);
    }

    @GetMapping("/list/coupon")
    @Operation(summary = "查询选择优惠券列表")
    public R<TableDataInfo<MarCouponPackCouponVO>> listCouponByReq(MarCouponPackCouponReqDTO marCouponPackCouponReqDTO) {
        TableDataInfo<MarCouponPackCouponVO> marCouponPackVOS = marCouponPackService.listCouponByReq(marCouponPackCouponReqDTO);
        return R.ok(marCouponPackVOS);
    }
}
